<%@ page language="java" import="com.ruohi.manage.*,java.util.*,com.ruohi.util.common.*,com.ruohi.util.dbutil.*,java.sql.*" pageEncoding="UTF-8"%><%
	response.setContentType("text/html; charset=UTF-8");
	Map adminInfo = (Map)session.getAttribute("adminInfo");
	DBHelper dbHelper = DBHelper.getInstance();
	String enumNo = CommonString.getFormatPara(request.getParameter("enumNo"));
	//公用表前缀
	String table_prefix = Env.getInstance().getProperty("table_prefix");
	//前置事件
	String eventBefore = CommonString.getFormatPara(request.getParameter("eventBefore"));
	//后置事件
	String eventAfter = CommonString.getFormatPara(request.getParameter("eventAfter"));
	StringBuffer sql = new StringBuffer();
	List values = new ArrayList(0);
	//验证码
	String rand = CommonString.getFormatPara(request.getParameter("rand"));
	if (null != rand && !"".equals(rand)) {
		String randStr = (String) session.getAttribute("rand");
		if (!rand.equals(randStr)) {
			out.print(2);
			return;
		}
	}
	Connection connection = null;
	int rs = 0;
	Map postMap = new HashMap();
	postMap.putAll(request.getParameterMap());
	if(null!=adminInfo){
		postMap.put("uuid",adminInfo.get("uuid"));
	}
	//如果有前置事件
	if(!"".equals(eventBefore)){
		Common.doPostHttpAsync(Common.getDomain(request)+"/backend/action/before.jsp",postMap,request.getCookies());
	}
	try{
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum(enumNo));
		connection.setAutoCommit(false);
		// 获得表名
		String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
		String idStr = CommonString.getFormatPara(request.getParameter("zd_id"));
		String ids = CommonString.getFormatPara(request.getParameter("del_id"));
		if (null != ids && ids.length() > 0) {// 删除
			sql.append("delete from " + tableName + " where uuid in (" + ids
					+ ") ");
			rs = dbHelper.execute(sql.toString(),connection);
		} else {// 增加或修改
			Enumeration params = request.getParameterNames();
			StringBuffer sqlback = new StringBuffer("(");
			StringBuffer sqlques = new StringBuffer("(");
			String name = "";
			String value = "";
			if (null != idStr && !"".equals(idStr)) {// 修改
				sqlback = new StringBuffer();
				while (params.hasMoreElements()) {
					name = (String) params.nextElement();
					if (name.equals("zd_id")) {
						continue;
					}
					if (name.startsWith("zd_") && !name.endsWith("_txt_val")) {
						value = CommonString.getFormatPara(request
								.getParameter(name));
						/**MD5密码修改，密码未修改时，不对密码进行操作*/
						if(name.equals("zd_passw") || name.equals("zd_password")){
							String password = CommonString.getFormatPara(request.getParameter("password"));
							if(password.equals(value)){
								continue;	
							}else{
								value = CommonEncrypt.MD5(value);	
							}
						}
						if(name.equals("zd_mem_passw")){//二手网专用
							String password = CommonString.getFormatPara(request.getParameter("mem_passw"));
							if(!password.equals(value) && !password.equals("")){//如果不相等，说明密码已经修改
								value = CommonEncrypt.MD5(value);
							}
						}
						/**/
						sqlback.append(name.substring(name.indexOf("zd_") + 3)
								+ "=?,");
						if (null == value) {
							value = "";
						}
						values.add(value);
					}
				}
				sqlback.setLength(sqlback.length() - 1);
				sql.setLength(0);
				sql.append(" update " + tableName + " set "
						+ sqlback.toString() + " where id = ? ");
				values.add(idStr);
				rs = dbHelper.executeUpdate(sql.toString(), values.toArray(),connection);
				postMap.put("updateId",CommonString.getFormatPara(request.getParameter("zd_id")));
			} else {// 增加
				while (params.hasMoreElements()) {
					name = (String) params.nextElement();
					if (name.startsWith("zd_") && !name.endsWith("_txt_val")) {
						value = request.getParameter(name);
						/*MD5加密*/
						if(name.equals("zd_passw")||name.equals("zd_password")){
							value = CommonEncrypt.MD5(value);	
						}
						//二手网专用
						if(name.equals("zd_mem_passw")){
							value = CommonEncrypt.MD5(value);	
						}
						/**/
						if (name.equals("zd_id")) {
							if(Env.getInstance().getProperty("dbtype").equals("mssql")){
								continue;
							}
							if(Env.getInstance().getProperty("dbtype").equals("mysql")){
								value = "0";
							}
						}
						sqlback.append(name.substring(name.indexOf("zd_") + 3));
						sqlback.append(",");
						sqlques.append("?,");
						if (null == value) {
							value = "";
						}
						values.add(value);
					}
				}
				values.add(CommonString.getUUID());
				if(null!=adminInfo){
					values.add(adminInfo.get("usern"));
				}else{
					values.add("front");
				}
				values.add(CommonDate.getToday("yyyy-MM-dd HH:mm:ss"));
				values.add(Common.getIp(request));
				sqlback.setLength(sqlback.length() - 1);
				sqlback.append(",uuid");
				sqlback.append(",add_user");
				sqlback.append(",add_date");
				sqlback.append(",add_ip");
				sqlback.append(")");
				sqlques.setLength(sqlques.length() - 1);
				sqlques.append(",?");
				sqlques.append(",?");
				sqlques.append(",?");
				sqlques.append(",?");
				sqlques.append(")");
				sql.setLength(0);
				sql.append(" insert into " + tableName + sqlback.toString()
						+ " values " + sqlques.toString());
				Integer keyId = dbHelper.executeUpdate(sql.toString(), values.toArray(),connection);

				postMap.put("keyId",keyId);
				if(null!=keyId&&keyId>0){
					rs = 1;
				}
			}
		}
		connection.commit();
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(connection);
	}
	//如果有后置事件
	if(!"".equals(eventAfter)){
		Common.doPostHttpAsync(Common.getDomain(request)+"/backend/action/after.jsp",postMap,request.getCookies());
	}
	out.print(rs); 
%>